<template>
	<view>
		<u-gap :height="200"></u-gap>
		<view class="u-flex u-flex-center">
			<u-image :src="src" width="550rpx" height="400rpx" mode="aspectFit"></u-image>
		</view>

		<view v-if="parstr == ''" class="" style="text-align: center; font-size: 28rpx">
			{{ $z.$t("应答等待中，请稍等") }}
			<text style="
          font-weight: bold;
          width: 40px;
          display: inline-block;
          margin-left: 5px;
          text-align: left;
        ">
				{{ dian }}
			</text>
		</view>

		<view v-else style="
        padding: 5px 0;
        text-align: center;
        color: #000000;
        font-size: 16px;
      " ng-if="parstr!=''">
			{{ $z.$t(parstr) }}
		</view>
		<zmodal ref="zmodal"></zmodal>
	</view>
</template>

<script>
	import config from "@/config/index.js";
	// import settingvue from "@/mixins/setting.vue";
	import qs from "qs";
	console.log(config, "config");
	let src = config.DataURLimg + "/21112/dd.gif";

	export default {
		data() {
			return {
				src: src,
				parstr: "",
				dian: ".",
				query: {},
				gettimes: [1, 3, 5, 10, 10, 10, 10],
				umodaldata: {},
				timesetInterval: "",
			};
		},
		// mixins: [settingvue],
		onLoad(query) {
			this.query = query;
			console.log('this.query', this.query);
		},
		mounted() {
			this.timesetInterval = setInterval(() => {
				if (this.dian.length >= 6) {
					this.dian = "·";
				} else {
					this.dian = this.dian + "·";
				}
			}, 300);
			this.getdata();

		},
		beforeDestroy() {
			clearInterval(this.timesetInterval);
		},
		methods: {

			async getdata() {
				let par = await this.$z.request(this.query.paramsUrl, {
					gtel: this.query.gtel,
					td: this.query.td,
				});
				if (par[0].par == "succeed") {
					// charge = 1   默认打开地锁
					if (this.query.paramsUrl == '/ChargeAskDs') {
						if (this.query.noChargePage) {
							uni.navigateTo({
								url: `/pages/StationCar/Stationgteltd/Stationgteltd?id=${this.query.id}&type=${this.query.type}`,
							});
						} else {
							// backType 要求返回 降地锁页面
							uni.navigateTo({
								url: `/pages/ChargeCarSys/ChargeCarSys?gtel=${this.query.gtel}_${this.query.td}&openChargeType=1&backType=1`,
							});
						}

					} else {
						uni.redirectTo({
							url: `/pages/ChargeUser/ChargeUser`,
						});
					}
				} else if (par[0].par == "err") {
					this.parstr = this.$z.$t("打开充电口失败");
					if (this.query.btntext == this.$z.$t("打开地锁")) {
						this.parstr = this.$z.$t("打开地锁失败");
						this.$refs.zmodal.init({
							content: this.$z.$t("打开地锁失败，请您换一台设备试试。"),
							showcancel: false,
							showconfirm: true,
							title: this.$z.$t("温馨提示"),
							confirmText: this.$z.$t("确认"),
							confirm: () => {
								this.$z.sys();
							},
							cancel: () => {}
						});
					}

					this.umodaldata = {
						show: true,
						content: this.$z.$t("打开充电口失败，请您换一台设备试试。"),
						title: "",
						showTitle: false,
						// showCancelButton: true,
						updatafn: () => {
							uni.navigateTo({
								url: "/pages/ChargeCarSys/ChargeCarSys?" +
									qs.stringify(this.query),
							});
						},
					};
				} else if (this.gettimes.length == 0) {
					if (par[0].par == "err") {
						this.parstr = this.$z.$t("打开充电口失败");
					} else if (par[0].par == "err_repeat") {
						this.parstr = this.$z.$t("硬件暂时无应答");
					} else {
						this.parstr = this.$z.$t("硬件暂时无应答");
					}
					this.umodaldata = {
						show: true,
						content: this.parstr + ',' + this.$z.$t("请您换一台设备试试。"),
						title: "",
						showTitle: false,
						// showCancelButton: true,
						updatafn: () => {
							uni.navigateTo({
								url: "/pages/ChargeCarSys/ChargeCarSys?" +
									qs.stringify(this.query),
							});
						},
					};
				} else {
					this.gettimes.shift();
					setTimeout((e) => {
						this.getdata();
					}, this.gettimes[0] * 1000);
				}
			},
		},
	};
</script>

<style></style>